<?php 
namespace Admin\Controller;
use \Think\Controller;

class UserController extends PublicController
{
	public function __construct()
	{
		parent::__construct();
		$this->assign('title','用户管理');
	}
	public function index()
	{
		// 得到分页查询的条件
		$map = array();
		if (!empty($_GET['username'])) {
			$map['username'] = array('LIKE',"%{$_GET['username']}%");
		}
		foreach($map as $key=>$val) {
			$Page->parameter[$key] = urlencode($val);
		}

		// 实例化前台用户表
		$user = M('user');

		$count = $user->where($map)->count();// 查询满足要求的总记录数
		$Page = new \Think\Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数(5)

		$show = $Page->show();// 分页显示输出
		// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		$userlist = $user->where($map)->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('page',$show);// 赋值分页输出


		// $userlist = $user->select();
		$this->assign('user',$userlist);
		$this->assign('locat','前台用户列表');
		$this->display('User/index');
	}

	public function stop()
	{
		$user = M('user');
		$id = $_GET['uid'];
		$where['uid'] = $id;
		$status = $user->where($where)->find();
		if ($status['status'] == 1) {
			$data['status'] = 0;
			$user->where($where)->save($data);
			$this->success('禁用成功!');
		} else {
			$data['status'] = 1;
			$user->where($where)->save($data);
			$this->success('启用成功!');
		}
		
	}
}
